﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Mengsk.ProxyDelivery.App.Extenstions;
using Mengsk.ProxyDelivery.Domain;

namespace Mengsk.ProxyDelivery.App.UI.Accounting
{
    /// <summary>
    /// SellerChargeUserControl.xaml 的交互逻辑
    /// </summary>
    public partial class SellerChargeUserControl : UserControl, IPlugin
    {
        SellerChargeService sellerChargeService = ServiceContainer.GetService<SellerChargeService>();

        public SellerChargeUserControl()
        {
            InitializeComponent();
        }

        public string Title
        {
            get { return "充值管理"; }
        }

        public Control UIControl
        {
            get { return this; }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.cbbPayTypes.Bind<Mengsk.ProxyDelivery.Domain.SellerChargePayType>();
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            this.pbBar.Parameters.Clear();
            this.pbBar.Parameters.Add("payType", this.cbbPayTypes.SelectedIndex);
            int sellerId = 0;
            int.TryParse(this.tbSellerId.Text, out sellerId);
            this.pbBar.Parameters.Add("sellerId", sellerId);
            this.pbBar.Parameters.Add("comment", this.tbComment.Text.Trim());
            this.pbBar.Parameters.Add("startCreateTime", this.dpStart.SelectedDate == null ? DateTime.MinValue : this.dpStart.SelectedDate.Value.Date);
            this.pbBar.Parameters.Add("endCreateTime", this.dpEnd.SelectedDate == null ? DateTime.MinValue : this.dpEnd.SelectedDate.Value.Date.AddDays(1));
            this.pbBar.StartPage();
        }

        private void btnMakeOk_Click(object sender, RoutedEventArgs e)
        {

        }

        private void PageBarUserControl_PageChanging(object sender, PageBar.PageChangeEventArgs e)
        {
            var item = this.sellerChargeService.GetByAll(e.GetParameter<SellerChargePayType>("payType"), e.GetParameter<int>("sellerId"), e.GetParameter<string>("comment"), e.GetParameter<DateTime>("startCreateTime"), e.GetParameter<DateTime>("endCreateTime"), e.CurrentPage - 1, e.PageSize);
            this.pbBar.Total = item.Total;
            this.pbBar.CurrentCount = item.Datas.Count;
            this.dgvSelelrCharges.ItemsSource = item.Datas;
        }



    }
}
